package xworker.gluon.attach;

import com.gluonhq.attach.vibration.VibrationService;
import org.xmeta.ActionContext;
import org.xmeta.Thing;

import java.util.List;

public class VibrateActions {
    public static void vibrate(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        List<String> pattern = self.doAction("getPattern", actionContext);
        long[] ps = new long[pattern.size()];
        for(int i=0; i<pattern.size(); i++){
            ps[i] = Long.parseLong(pattern.get(i).trim());
        }

        VibrationService.create().ifPresent(vibrationService -> vibrationService.vibrate(ps));
    }
}
